<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="房屋标题" prop="houseTitle">
        <el-input v-model="queryParams.houseTitle" placeholder="请输入房屋标题" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="房屋地址" prop="address">
        <el-input v-model="queryParams.address" placeholder="请输入房屋地址" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="房源面积" prop="rentArea">
        <el-input v-model="queryParams.rentArea" placeholder="请输入房源面积" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="房源建成年份" prop="yearBuilt">
        <el-input v-model="queryParams.yearBuilt" placeholder="请输入房源建成年份" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="房屋名称" prop="houseName">
        <el-input v-model="queryParams.houseName" placeholder="请输入房屋名称" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="房屋的装修情况" prop="renovation">
        <el-input v-model="queryParams.renovation" placeholder="请输入房屋的装修情况" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="房屋的出租情况" prop="grounding">
        <el-input v-model="queryParams.grounding" placeholder="请输入房屋的出租情况" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="房屋的供暖方式" prop="heating">
        <el-input v-model="queryParams.heating" placeholder="请输入房屋的供暖方式" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="房屋的绿化率" prop="greenPercentage">
        <el-input v-model="queryParams.greenPercentage" placeholder="请输入房屋的绿化率" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="房屋的保护措施或附加信息" prop="protection">
        <el-input v-model="queryParams.protection" placeholder="请输入房屋的保护措施或附加信息" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
<!-- 弹框 -->
<el-drawer
  title="我是标题"
  :visible.sync="drawer"
  size="80%"
  :with-header="false">
  <el-row  :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openFormone()"
                  >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
                   >导出</el-button>
      </el-col>
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
  <el-table v-loading="loading" :data="houseInfo" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="房屋朝向/楼层/使用面积/" align="center" prop="name" />
      <el-table-column label="数值" align="center" prop="description" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
        <el-button size="mini" type="text" icon="el-icon-edit" @click="openFormtwo(scope.row.id)"
                     >修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDele(scope.row)"
                     >删除</el-button>
                     </template>
      </el-table-column>
    </el-table>

</el-drawer>
    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
                  >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
                   >导出</el-button>
      </el-col>
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

      <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="房屋ID" align="center" prop="id" />
      <el-table-column label="房屋标题" align="center" prop="houseTitle" />
      <el-table-column label="房屋地址" align="center" prop="address" />
      <el-table-column label="房源面积" align="center" prop="rentArea" />
      <el-table-column label="房源建成年份" align="center" prop="yearBuilt" />
      <el-table-column label="房屋名称" align="center" prop="houseName" />
      <el-table-column label="房屋的装修情况" align="center" prop="renovation" />
      <el-table-column label="房屋的出租情况" align="center" prop="grounding" />
      <el-table-column label="房屋的供暖方式" align="center" prop="heating" />
      <el-table-column label="房屋的绿化率" align="center" prop="greenPercentage" />
      <el-table-column label="房屋的保护措施或附加信息" align="center" prop="protection" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)"
                     >修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     >删除</el-button>
          <el-button @click="getListone(scope.row)" type="text" style="margin-left: 16px;" size="mini">
                     点我打开
                     </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
    <!-- 对话框(添加 / 修改) -->
    <HouseInfoForm ref="formRef" @success="getList" />
    <HouseMetaInfoForm  ref="formRefone" @success="getListone" />
    </div>
</template>

<script>
import * as HouseInfoApi from '@/api/system/houseinfo';
import HouseInfoForm from './HouseInfoForm.vue';
import HouseMetaInfoForm from './HouseMetaInfoForm.vue';

export default {
  name: "HouseInfo",
  components: {
          HouseInfoForm,
          HouseMetaInfoForm
          
  },
  data() {
    return {
      // 房屋信息id
      houseIdtest:{},
      //房屋元信息
      houseInfo:{},
      // 弹窗标题
      drawer: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
              // 总条数
        total: 0,
      // 房屋信息列表
      list: [],
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 选中行
      currentRow: {},
      // 查询参数
      queryParams: {
        offset: 1,
         size: 10,
        houseTitle: null,
        address: null,
        rentArea: null,
        yearBuilt: null,
        houseName: null,
        renovation: null,
        grounding: null,
        heating: null,
        greenPercentage: null,
        protection: null,
        createTime: [],
      },
            };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    async getList() {
      try {
      this.loading = true;
         const res = await HouseInfoApi.getHouseInfoPage(this.queryParams);
       
        this.list = res.data.records;
        this.total = res.data.total;
      } finally {
        this.loading = false;
      }
    },
   async getListone(row) {
      try {
       
        this.drawer = true;
        this.loading = true;
        const res= await HouseInfoApi.getHouseMetaInfoid(row.id);
        this.houseInfo=res.data[0].metaList;
        this.houseIdtest=res.data[0].houseId;
        console.log(res);
      }finally {
        this.loading = false;
        this.getListone()
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 添加/修改操作 */
    openForm(id) {
      this.$refs["formRef"].open(id);
    },
    openFormone(id){
      const houseId=this.houseIdtest
      this.$refs["formRefone"].gethouseId(houseId)
      this.$refs["formRefone"].open(id);
    },
  openFormtwo(id){
      const houseId=this.houseIdtest
      this.$refs["formRefone"].open(id);
     this.$refs["formRefone"].gethouseId(houseId)
    },
    /** 删除按钮操作 */
    async handleDelete(row) {
      const id = row.id;
      await this.$modal.confirm('是否确认删除房屋信息编号为"' + id + '"的数据项?')
      try {
       await HouseInfoApi.deleteHouseInfo(id);
       await this.getList();
       this.$modal.msgSuccess("删除成功");
      } catch {}
    },
    
    /** 删除按钮操作 */
    async handleDele(row) {
      const id = row.id;
      await this.$modal.confirm('是否确认删除房屋信息编号为"' + id + '"的数据项?')
      try {
       await HouseInfoApi.deleteHouseMetaInfo(id);
       this.$modal.msgSuccess("删除成功");
       this.getListone();
      } catch {}
    },
    
    /** 导出按钮操作 */
    async handleExport() {
      await this.$modal.confirm('是否确认导出所有房屋信息数据项?');
      try {
        this.exportLoading = true;
        const data = await HouseInfoApi.exportHouseInfoExcel(this.queryParams);
        this.$download.excel(data, '房屋信息.xls');
      } catch {
      } finally {
        this.exportLoading = false;
      }
    },
              }
};
</script>
